package logic

import (
	"cart_srv/models/redis"
	"context"
	"errors"

	"cart_srv/cart_srv"
	"cart_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CheckedCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCheckedCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckedCartLogic {
	return &CheckedCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CheckedCartLogic) CheckedCart(in *cart_srv.CheckedCartRequest) (*cart_srv.CheckedCartResponse, error) {
	// todo: add your logic here and delete this line
	if redis.CartIsNilOrNotNil(int(in.UserId)) {
		return nil, errors.New("购物车为空")
	}
	err := redis.CheckedCart(int(in.UserId))
	if err != nil {
		return nil, err
	}
	return &cart_srv.CheckedCartResponse{}, nil
}
